﻿using MyHospital.DAL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MyHospital.BLL
{
    public class Department
    {
        MyHospitalDataContext db = new MyHospitalDataContext();
        public void DeleteDepartment(string DepartmentID)
        {
            DAL.Department department = (from c in db.Department
                                         where c.departId == int.Parse(DepartmentID)
                                         select c).FirstOrDefault();
            if (department != null)
            {
                db.Department.DeleteOnSubmit(department);
                db.SubmitChanges();
            }
        }
        public bool isDepartExit(string Name)
        {
            DAL.Department department = (from c in db.Department
                                         where c.departName == Name
                                         select c).FirstOrDefault();
            if (department == null) return true;
            else return false;
        }
        public void InsertDepartment(string Name, string Dec)
        {
            DAL.Department department = new DAL.Department();
            department.departName = Name;
            department.introduce = Dec;
            db.Department.InsertOnSubmit(department);
            db.SubmitChanges();
        }
        public List<DAL.Department> GetDepartmentsList(string name)//模糊查找
        {
            var result = (from c in db.Department
                         where System.Data.Linq.SqlClient.SqlMethods.Like(c.departName ,"%" + name + "%")
                         select c).ToList();
            return result;
        }
    }
}
